import { fabric } from 'fabric';

import ObjectPool from './ObjectPool';

class Diamond extends fabric.Polygon {
  constructor(options = {}) {
    const points = [
      { x: 0, y: -50 },  // 上
      { x: 50, y: 0 },   // 右
      { x: 0, y: 50 },   // 下
      { x: -50, y: 0 },  // 左
    ];

    super(points, {
      fill: '#8e44ad',
      strokeWidth: 1,
      stroke: '#000000',
      selectable: true,
      cornerSize: 10,
      transparentCorners: false,
      hasRotatingPoint: true,
      padding: 5,
      ...options,
      id: '',  // 添加id属性
    });

    // 确保控制点颜色与边框颜色一致
    this.set({
      cornerColor: this.stroke,
      borderColor: this.stroke,
    });
  }
}

// 创建一个全局的菱形对象池
const diamondPool = new ObjectPool(() => new Diamond());

// 导出Diamond类和diamondPool
export { Diamond, diamondPool };
export default Diamond;
